package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/9/29 23:08
 * @Version 1.0
 */
public class Solution605 {
    public static boolean canPlaceFlowers(int[] flowerbed, int n) {
        int length = flowerbed.length;
        if (n > (length + 1) / 2) {
            return false;
        }
        int res = 0;
        int start;
        int end;
        for (int i = 0; i < length; i++) {
            if (i == 0) {
                start = 0;
            } else {
                start = flowerbed[i - 1];
            }
            if (i == length - 1) {
                end = 0;
            } else {
                end = flowerbed[i + 1];
            }
            if (start == 0 && flowerbed[i] == 0 && end == 0) {
                flowerbed[i] = 1;
                res++;
            }
        }
        return n <= res;
    }

    public static void main(String[] args) {

    }
}
